 //
//  LoginViewController.m
//  DigitalCampus
//
//  Created by 刘占宇 on 16/3/26.
//  Copyright © 2016年 刘占宇. All rights reserved.
//

#import "LoginViewController.h"
#import "LZYNetworkHelper.h"
#import "User.h"
@interface LoginViewController ()<UITextFieldDelegate,UIGestureRecognizerDelegate>
@property (nonatomic,copy) NSString *appurl;
@property (nonatomic,assign) BOOL isdianji,isremeber,isupdate;
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *pwd;
@property (weak, nonatomic) IBOutlet UIButton *login;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTextField];
}

- (void)setTextField{
    [self.username setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.username setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
    [self.pwd setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.pwd setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
    self.pwd.secureTextEntry = YES;
    self.login.layer.cornerRadius = 4;
    self.login.layer.masksToBounds = YES;
    self.login.layer.borderWidth = 0.5; //边框
    self.login.layer.borderColor = [UIColor whiteColor].CGColor;
    if ([[User shareInstance]getLoginState] == LoginOut && ![NSString isEmpty:[[User shareInstance]getUserName]]) {
        self.username.text = [[User shareInstance]getUserName];
        self.pwd.text = [[User shareInstance]getPassWord];
    }
}

- (IBAction)login:(id)sender {
    if ([NSString isEmpty:self.username.text])[LZYShowMsg showText:@"用户名不能为空"];else{
        if ([NSString isEmpty:self.pwd.text])[LZYShowMsg showText:@"密码不能为空"];else{
            NSDictionary *parametersDic = @{@"loginName":self.username.text,@"pwd":self.pwd.text};
            [LZYNetworkHelper POST:loginUrl parameters:parametersDic success:^(id responseObject) {
                [[User shareInstance] loginIn];
                NSString *userFace;
                if ([[responseObject allKeys] containsObject:@"face"]) {
                    userFace = responseObject[@"face"];
                }else{
                    userFace = responseObject[@""];
                }
                [[User shareInstance]setUserName:self.username.text passWord:self.pwd.text accessToken:responseObject[@"tocken"] userId:responseObject[@"uid"] userFace:userFace userOrignName:responseObject[@"name"]];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"login" object:@YES];
            } failure:^(NSError *error) {
             
            } showHub:YES];
        }
    }
}

@end
